<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function question6(){
            const a = 1;
            //a = 0; 报错 const 声明的变量都会被认为是常量，意思就是它的值被设置完成后就不能再修改了
            const student = {
                name: 'Sam',
                age: 22,
                sex: '男'
            };
            student.name = 'yy';// 不报错
            //student  = { name: 'yy' }; 报错  如果const的是一个对象，对象所包含的值是可以被修改的。抽象一点儿说，就是对象所指向的地址没有变就行

            //ES6之前
            document.getElementById("question6").innerText = "This demonstrates the output of HTML content to the page, including student's" + name + " and so on."
            //ES6使用${}
            document.getElementById("question6").innerText = "This demonstrates the output of HTML content to the page, including student's ${name} and so on."

            // ES5
            var add = function (a, b) {
                return a + b;
            };
            // 使用箭头函数
            var add = (a, b) => a + b;

            // ES6之前，当未传入参数时，text = 'default'；
            function printText(text) {
                text = text || 'default';
                console.log(text);
            }
            // ES6
            function printText(text = 'default') {
                console.log(text);
            }

            // 数组
            // const student = ['Sam', 22, '男'];

            // ES5
            const name1 = student.name;
            const age1 = student.age;
            const sex1 = student.sex;
            console.log(name + ' --- ' + age + ' --- ' + sex);

            // ES6
            const { name, age, sex } = student;
            console.log(name + ' --- ' + age + ' --- ' + sex);

            //ES6 允许在对象中使用 super 方法：
            var parent = {
                foo() {
                    console.log("Hello from the Parent");
                }
            }

            var child = {
                foo() {
                    super.foo();
                    console.log("Hello from the Child");
                }
            }

            Object.setPrototypeOf(child, parent);
            child.foo(); // Hello from the Parent
                         // Hello from the Child

            //for...of 用于遍历一个迭代器        for...in 用来遍历对象中的属性
            let letters = ['a', 'b', 'c'];
            letters.size = 3;
            for (let letter of letters) {
                console.log(letter);
            }
            let stus = ["Sam", "22", "男"];
            for (let stu in stus) {
                console.log(stus[stu]);
            }

            //ES6 中支持 class 语法
            class Student {
                constructor() {
                    console.log("I'm a student.");
                }

                study() {
                    console.log('study!');
                }

                static read() {
                    console.log("Reading Now.");
                }
            }
            console.log(typeof Student); // function
            let stu = new Student(); // "I'm a student."
            stu.study(); // "study!"
            stu.read(); // "Reading Now."
        }

        class Phone {
            constructor() {
                console.log("I'm a phone.");
            }
        }
        class MI extends Phone {
            constructor() {
                super();
                console.log("I'm a phone designed by xiaomi");
            }
        }

        let mi8 = new MI();
        //extends 允许一个子类继承父类，需要注意的是，子类的constructor 函数中需要执行 super() 函数。
    </script>
</head>
<body>

</body>
</html>